package com.aliyun.heiyu.powermaster.server.util;

import com.aliyun.heiyu.powermaster.server.dao.entity.EmailPropertiesConfig;
import com.aliyun.heiyu.powermaster.server.dao.entity.IscMail;
import com.aliyun.heiyu.powermaster.server.rotary.dao.AirDAO;
import com.aliyun.heiyu.powermaster.server.rotary.dao.impl.AirDAOImpl;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


/**
 * ISC邮件构建类
 * 
 * @author WANGHT ON 2020年5月23日 16:46:11
 *
 */
public class IscMailBuilder implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private static AirDAO airDAO =new AirDAOImpl();
	/**
	 * 构建
	 * 
	 * @param msg
	 * @param subject
	 * @return
	 */
	public static IscMail builder(String subject, String msg) {
		IscMail iscMail = new IscMail();
		//数据库 查询配置文件出来
        EmailPropertiesConfig emailPropertiesConfig = airDAO.getEmailPropertiesConfig("1");
		if(StringUtils.isNoneBlank(msg) && emailPropertiesConfig != null) {
            List<String> receiverList = Arrays.asList(emailPropertiesConfig.getReceiver().split(","));
            iscMail.setHost(emailPropertiesConfig.getHost());
            iscMail.setPort(emailPropertiesConfig.getPort());
            iscMail.setUsername(emailPropertiesConfig.getUsername());
            iscMail.setPdSender(emailPropertiesConfig.getPd_sender());
            iscMail.setSender(emailPropertiesConfig.getSender());
            iscMail.setUseSSL(emailPropertiesConfig.getUse_ssl());
            iscMail.setUseTLS(emailPropertiesConfig.getUse_tls());
            iscMail.setReceiver(receiverList);
            iscMail.setSubject(subject);
            iscMail.setMessage(msg);
		}
		return iscMail;
	}

}
